namespace IniTechCaash.WebApplication.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using IniTechCaash.WebApplication.Models;

    internal sealed class Configuration : DbMigrationsConfiguration<IniTechCaash.WebApplication.Models.ApplicationDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(IniTechCaash.WebApplication.Models.ApplicationDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            var idManager = new IdentityManager();
            idManager.CreateRole("Admin");
            idManager.CreateRole("Manager");
            idManager.CreateRole("User");

            ApplicationUser corey = new ApplicationUser
            {
                Email = "wmasters@spsu.edu",
                IsEnabled = true,
                LoginTries = 0,
                UserName = "wmasters",
            };
            idManager.CreateUser(corey, "Initech#2014");
            idManager.AddUserToRole(corey.Id, "Admin");
            idManager.AddUserToRole(corey.Id, "Manager");
            idManager.AddUserToRole(corey.Id, "User");

            ApplicationUser jose = new ApplicationUser
            {
                Email = "jpinott@spsu.edu",
                IsEnabled = true,
                LoginTries = 0,
                UserName = "jpinott",
            };
            idManager.CreateUser(jose, "Initech#2014");
            idManager.AddUserToRole(jose.Id, "Admin");
            idManager.AddUserToRole(jose.Id, "Manager");
            idManager.AddUserToRole(jose.Id, "User");

            ApplicationUser testManagerJose = new ApplicationUser
            {
                Email = "jpinott@spsu.edu",
                IsEnabled = true,
                LoginTries = 0,
                UserName = "testManagerJose",
            };
            idManager.CreateUser(testManagerJose, "Initech#2014");
            idManager.AddUserToRole(testManagerJose.Id, "Manager");

            ApplicationUser testManagerCorey = new ApplicationUser
            {
                Email = "wmasters@spsu.edu",
                IsEnabled = true,
                LoginTries = 0,
                UserName = "testManagerCorey",
            };
            idManager.CreateUser(testManagerCorey, "Initech#2014");
            idManager.AddUserToRole(testManagerCorey.Id, "Manager");

            ApplicationUser testUserJose = new ApplicationUser
            {
                Email = "jpinott@spsu.edu",
                IsEnabled = true,
                LoginTries = 0,
                UserName = "testUserJose",
            };
            idManager.CreateUser(testUserJose, "Initech#2014");
            idManager.AddUserToRole(testUserJose.Id, "User");

            ApplicationUser testUserCorey = new ApplicationUser
            {
                Email = "wmasters@spsu.edu",
                IsEnabled = true,
                LoginTries = 0,
                UserName = "testUserCorey",
            };
            idManager.CreateUser(testUserCorey, "Initech#2014");
            idManager.AddUserToRole(testUserCorey.Id, "User");

            ApplicationUser wflowers = new ApplicationUser
            {
                Email = "wtflowers@live.com",
                IsEnabled = true,
                LoginTries = 0,
                UserName = "wflowers",
            };
            idManager.CreateUser(wflowers, "Initech#2014");
            idManager.AddUserToRole(wflowers.Id, "Admin");

            ApplicationUser jmamo = new ApplicationUser
            {
                Email = "jmamo@spsu.edu",
                IsEnabled = true,
                LoginTries = 0,
                UserName = "jmamo",
            };
            idManager.CreateUser(jmamo, "Initech#2014");
            idManager.AddUserToRole(jmamo.Id, "Admin");
        }
    }
}
